﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.RenameTool.RuleBase
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using System.Windows.Forms;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.RenameTool;

[Serializable]
public abstract class RuleBase
{
  protected int ArgsLength;
  protected RuleState ruleState;

  public abstract RuleMessage Execute(List<string> objects);

  public abstract object[] Args { get; set; }

  public abstract string DisplayString { get; }

  public abstract string Header { get; }

  public abstract RuleBase CreateInstance();

  public abstract RuleWindowBase CreateWindow(Window parent);

  public abstract int Position { get; }

  public RuleState State => this.ruleState;

  public bool? ShowWindow(Window parent, bool loadArgs = false)
  {
    RuleWindowBase window = this.CreateWindow(parent);
    ((Window) window).Closed += new EventHandler(this.window_Closed);
    ((Window) window).Closing += new CancelEventHandler(this.window_Closing);
    ((Window) window).Title = this.Header;
    if (loadArgs)
      window.Args = this.Args;
    return ((Window) window).ShowDialog();
  }

  private void window_Closing(object sender, CancelEventArgs e)
  {
    bool? dialogResult = ((Window) sender).DialogResult;
    bool flag = true;
    if (!(dialogResult.GetValueOrDefault() == flag & dialogResult.HasValue))
      return;
    RuleMessage ruleMessage = ((RuleWindowBase) sender).Validate();
    if (ruleMessage.Success)
    {
      this.Args = (sender as RuleWindowBase).Args;
    }
    else
    {
      string str = ruleMessage.Message;
      if (str == "")
        str = "Some of the values are invalid";
      int num = (int) TxMessageBox.Show(str, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
      e.Cancel = true;
    }
  }

  private void window_Closed(object sender, EventArgs e)
  {
    ((Window) sender).Closed -= new EventHandler(this.window_Closed);
    ((Window) sender).Closing -= new CancelEventHandler(this.window_Closing);
    sender = (object) null;
  }
}
